<template>
  <div id="app">
      <navMenu/>

      <keep-alive>
        <router-view class="router-view"/>
      </keep-alive>

  </div>
</template>

<script>
import navMenu from './components/nav-menu.vue'

export default {
    name: 'index',
    components: { navMenu },
    data() {
        return {
            msg: 'index'
        }
    },
    methods: {
      // 跳转到login页面
      toLogin() {
        let routeUrl = this.$router.resolve({
          path: "/login",
        });
        window.open(routeUrl.href, "_self");
      }
    },
    created() {
      // 判断cookie中是否含有token
      if (this.$cookies.isKey("token")) {
          const token = this.$cookies.get("token")

          // 判断令牌是否合法
          this.$http({
              url: '/sysAdmin/isLogged',
              method: 'POST',
              data: token
          }).then(res => {
            // 200:令牌合法;其他:令牌不合法
            if (res.data.code !== 200) {
              this.toLogin()
            }
          })
      } else {
        // cookie中没有token
        this.toLogin()
      }
    }
}
</script>

<style>
*{
  margin: 0;
  padding: 0;
}

#app{
  display: flex;
  width: 100vw;
  height: 100vh;
}

.router-view{
  width: calc(100vw - 200px);
  height: 100vh;
  /* background-color: #dedede; */
}
</style>
